package com.example.om_export.common.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author wb-ycl473317
 */
public class FileUtil {

    /**
     * 输入流转换成二进制输出流
     * @param inputStream
     * @return
     */
    public static ByteArrayOutputStream InputStreamToByte(InputStream inputStream){
        if(inputStream==null){
            return null;
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        try {
            byte[] bit = new byte[1024];
            int len;
            while((len=inputStream.read(bit))!=-1){
                byteArrayOutputStream.write(bit,0,len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return byteArrayOutputStream;
    }
}
